<?php
	session_start();
	require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/acc_conn.php';
    require_once $_SERVER['DOCUMENT_ROOT'] . '/accHestia/src/svr/com/rpc_com.php';
    
    function dorpc_login($data, &$res) {
		$pdb = new acc_DB();

		$loginId = $data["loginId"];
		$pwd = $data["pwd"];
		$cond = "where loginId='" . $loginId . "' and pwd = '" . $pwd . "'";
		$ssql = "select count(*) as __cc from users " . $cond;
		$ret = $pdb->qw($ssql, "__cc");

		if (1 == $ret) {
			$_SESSION["acc_logined"] = "yes";
			$_SESSION["loginedId"] = $data["loginId"];
            set_res_OK($res, "input data:" . var_export($data, true));
		} else {
			$_SESSION["acc_logined"] = "no";
			$_SESSION["loginedId"] = "";
            set_res_NG($res, "query NG:" . $ssql);
		}
    }

    function dorpc_logout($data, &$res) {
		$_SESSION["acc_logined"] = "no";
		$_SESSION["loginedId"] = "";
        set_res_OK($res);
    }

    function dorpc_uid_unique_check($data, &$res){
		$pdb = new acc_DB();
		$ssql = "select * from users where loginId = '" . $data["loginId"] . "'";	

		if (0 == $pdb->afr($ssql)) {
			set_res_OK($res, $ssql);
		} else {
            set_res_NG($res, $ssql);
        }
    }

	function dorpc_regist_new($data, &$res){
        $loginId = $data["loginId"];
        $upwd = $data["pwd"];
        $email = $data["email"];

		$pdb = new acc_DB();
		$ssql = "insert into users(loginId, pwd, email) values('" . $loginId . "', '" . $upwd . "', '" . $email . "');";
		if(!$pdb->q($ssql)){
            set_res_NG($res, $ssql);
			return;
		}
        set_res_OK($res, $ssql);
	}
?>